<?php
namespace Admin\Controller;

class CommentController extends AdminController {

	public function index(){
		$key=I("key");
		if(isset($key)){
			$map['content']=array("like","%".$key."%");
			$this->assign('key', $key);
		}
		$obj = M('Comment');
		$count = $obj->where($map)->count();
		import("Common.ORG.Page");
		$page = new \Page($count, 20);
		$show = $page->show();
		$list = $obj->where($map)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
		$this->assign('list', $list);
		$this->assign('page', $show);
		$this->display();
	}

	public function open(){
		$map['id']=I('get.id');
        M('Comment')->where($map)->setField('status',1);
        redirect ($_SERVER['HTTP_REFERER']);
	}
	public function close(){
		$map['id']=I('get.id');
        M('Comment')->where($map)->setField('status',0);
        redirect ($_SERVER['HTTP_REFERER']);
	}


	public function del(){	
		$id=I('post.selectedids');

		if($id==''){
			$state = L("_no_selected");
		}else{
			foreach ($id as $v) {
				$obj = M('Comment');
				$where['id'] = $v;
				$obj->where($where)->delete();
			}
			$state = 'SUCCESS';
	        $message = L('_action_success');
	        $url = U('Comment/index');
		}
		echo $this->echo_json_str($state,$message,$url);
    }
}
?>